home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Can be C a so strange language ???. Problem with a function returning a pointer...
- Date: Tue, 23 Jan 96 21:02:00 GMT
- Organization: none
- Message-ID: <822430920snz@genesis.demon.co.uk>
- References: <4e015j$drt@hermes.fundp.ac.be> <822324787snz@genesis.demon.co.uk> <4e2pri$pk9@nntpd2.cxo.dec.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4e2pri$pk9@nntpd2.cxo.dec.com>
- b_hibbert@csc32.enet.dec.com "Brian Hibbert" writes:
-
- >Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
- >
- >>This looks rather convoluted and appears to go into an infinite loop if it
- >>hits the end of the list. Maybe you wanted something like:
- >>
- >>{
- >> while (position_ptr != NULL && position_ptr->res_number != residue_number)
- >> position_ptr = position_ptr->cooh_ptr;
- >>
- >> return position_ptr;
- >>}
- >
- >I had almost posted an identical routine, but I decided to move the
- >comparison of the residue_number outside the while test condition. If
- >the position_ptr is NULL and if the right side of the && operator is
- >evaluated first, the code will cause a segmentation fault or access
- >violation on some architectures. Not knowing the system that this will
- >be run on, and not knowing the order that the compiler does the
- >evaluation, I think it's best to err on the side of caution.
-
- The code is correct because && enforces order of evaluation and
- short-circuiting.
-
- Please, if you post a response please don't email it as well (unless
- somebody asked for that). I've already emailed a reply to this and prefer
- not to have to answer the same thing twice. If you do post and email, make
- that clear in the email.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-